<%@ page language="java" import="java.util.*,com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.ArrayList,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<User> users = companyInfo.users;
  List<Group> allGroups = companyInfo.getAllGroups();
  List<Map<String, Object>> customerCategorys = companyInfo.customerCategorys;
  List<Map<String, Object>> companyTags = companyInfo.tags;

  // 生成有效用户列表（本部门的，以及所有下属部门的员工）
  List<User> listUsers = new ArrayList<User>();
  int num = 0;
  String moreClass = "";
  for (User u : users) {
    if (!companyInfo.isGroupAdmin(user, u.groupId)) {
      continue;
    }
    num ++;
    listUsers.add(u);
  }

  // 生成有效部门列表（本部门及所有下属部门）
  List<Group> listGroups = new ArrayList();
  if (user.isAdmin) {
    if (allGroups != null) {
      listGroups.addAll(allGroups);
    }
  } else {
    Group group = companyInfo.getGroupById(user.groupId);
    if (group != null) {
      listGroups.add(group);
      List<Group> childrenGroups = group.getAllChildren();
      if (childrenGroups != null) {
        listGroups.addAll(childrenGroups);
      }
    }
  }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>统计分析</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.sparkline.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/raphael-min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/morris.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/report.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/json2.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
</head>
<body class="dashboard report">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <table>
    <tr>
      <td class="main-body">
        <div class="topHeader">
          <div class='leftMenu'><span>统计分析</span></div>
        </div>
        <div class="header">销售结果统计
          <div class="right date">
            <div class="input-prepend input-group"><span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="searchDate_deal" class="daterangepickerinput form-control" value="" /></div>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar">
              <h1>全部销售机会数量统计 <span id="totalDealsNum"></span></h1>
              <div class="switchMiniTab">
                <ul v="deal">
                  <li class="on"><a class="item" href="#" v="0">全部</a></li>
                  <li><a class="item" href="#" v="1">跟踪中</a></li>
                  <li><a class="item" href="#" v="2">成功</a></li>
                  <li class="last"><a class="item" href="#" v="3">失败</a></li>
                </ul>
              </div>
              <table id="dealsNums">
<%
  int index = 0;
  for (User u:listUsers) {
    if (index < 5) {
%>
              <tr v="0" id="dealsNums_<%=u.userId%>"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	} else {
%>
              <tr v="0" id="dealsNums_<%=u.userId%>" class="more"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
    index++;
  }
%>
              </table>
<%
	if (index > 5) {
%><div><a href="#dealsNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
            <td class="lineChar second">
              <h1>指定时间段成交金额 <span id="totalDealsMoneyNum"></span></h1>
              <table id="dealsMoney" style="padding-top:40px;">
<%
	index = 0;
  for (User u:listUsers) {
    if (index < 5) {
%>
              <tr v="0" id="dealsMoney_<%=u.userId%>"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	} else {
%>
              <tr v="0" id="dealsMoney_<%=u.userId%>" class="more"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
    index++;
  }
%>
              </table>
<%
	if (index > 5) {
%><div><a href="#dealsMoney" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
          </tr></table>
        </div>
        <div class="header">客户信息统计
          <div class="right date">
            <div class="input-prepend input-group"><span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="searchDate_customer" class="daterangepickerinput form-control" value="" /></div>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar">
              <h1>总客户数 <span id="totalCustomerNum"></span></h1>
              <table id="totalNums" style="padding-top:40px;">
<%
	index = 0;
  for (User u:listUsers) {
    if (index < 5) {
%>
              <tr v="0" id="totalNums_<%=u.userId%>"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	} else {
%>
              <tr v="0" id="totalNums_<%=u.userId%>" class="more"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
    index++;
  }
%>
              </table>
<%
	if (index > 5) {
%><div><a href="#totalNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
            <td class="lineChar second">
              <h1>指定时间段客户数量统计 <span id="totalContactCustomerNums"></span></h1>
              <div class="switchMiniTab">
                <ul v="customer">
                  <li class="on"><a class="item" href="#" v="0">已联系</a></li>
                  <li><a class="item" href="#" v="1">新增加</a></li>
                  <li class="last"><a class="item" href="#" v="2">下次联系</a></li>
                </ul>
              </div>
              <table id="totalContactNums">
<%
	index = 0;
  for (User u:listUsers) {
    if (index < 5) {
%>
              <tr v="0" id="totalContactNums_<%=u.userId%>"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	} else {
%>
              <tr v="0" id="totalContactNums_<%=u.userId%>" class="more"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
    index++;
  }
%>
              </table>
<%
	if (index > 5) {
%><div><a href="#totalContactNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
          </tr></table>
        </div>
        <div class="header">客户分类总数量统计
          <div class="right date">
            <select id="category_userId">
              <%
              	if (user.isAdmin()) {
              %>
              <option value="">所有数据（包含公海数据）</option>
              <option value="u_*">所有员工</option>
              <option value="g_0">无部门员工</option>
              <%
                for (User u:listUsers) {
                    if (u.groupId == 0) {
              %>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%
              	    }
                }
              } else if (user.isGroupAdmin()){
              %>
              <option value="u_*">所有员工</option>
              <%
              	}
              %>
              <%
              	for (Group group:listGroups) {
              %>
              <option value="g_<%=group.getId()%>">部门：<%=Util.HTMLEncode(group.getName())%></option>
              <%
                  for (User u:listUsers) {
                    if (u.groupId == group.getId()) {%>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%
              	    }
                  }
                }%>
            </select>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar"><div class="char" id="customerchar"></div></td>
            <td class="lineChar second">
              <h1>客户分类详细 <span id="totalCategoryNums"></span></h1>
              <table id="customerCategoryNums">
              <tr v="0" id="customerCategoryNums_0"><td class="member" title="无分类">无分类</td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	num = 0;
  moreClass = "";
  for (Map<String, Object> category:customerCategorys) {
    if (num > 4) {
      moreClass = "more";
    }
    num ++;
%>
              <tr v="0" id="customerCategoryNums_<%=category.get("CategoryId")%>" class="<%=moreClass%>"><td class="member" title="<%=Util.HTMLEncode((String)category.get("CategoryName"))%>"><%=Util.HTMLEncode(Util.showMaxLen((String)category.get("CategoryName"), 6))%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
%>
              </table>
<%
	if (num > 5) {
%><div><a href="#customerCategoryNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
            </tr></table>
        </div>
        <div class="header">客户分类修改统计（一）
          <div class="right" style="position:relative;padding:10px;">
            <div style="float:left;" class="input-prepend input-group"><span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="searchDate_customer_change" class="daterangepickerinput form-control" value="" /></div>
            <select id="category_change_userId" style="float:left;padding:4px 1px 4px 4px;margin-left:10px;">
            <%
            	if (user.isAdmin()) {
            %>
              <option value="">所有数据（包含公海数据）</option>
              <option value="u_*">所有员工</option>
              <option value="g_0">无部门员工</option>
              <%
              	for (User u:listUsers) {
                  if (u.groupId == 0) {%>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%
              	  }
                }
              } else if (user.isGroupAdmin()) {
              %>
              <option value="u_*">所有员工</option>
              <%
            	}
              for (Group gp:listGroups) {%>
              <option value="g_<%=gp.getId()%>">部门：<%=Util.HTMLEncode(gp.getName())%></option>
              <%
                for (User u:listUsers) {
                  if (u.groupId == gp.getId()) {%>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%
              	  }
                }
              }
              %>
            </select>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar"><div class="char" id="categorychangechar"></div></td>
            <td class="lineChar second">
              <h1>客户分类修改详细 <span id="totalCategoryChangeNums"></span></h1>
              <table id="customerCategoryChangeNums">
              <tr v="0" id="customerCategoryChangeNums_0"><td class="member" title="无分类">无分类</td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	num = 0;
  moreClass = "";
  for (Map<String, Object> category:customerCategorys) {
    if (num > 4) {
      moreClass = "more";
    }
    num ++;
%>
              <tr v="0" id="customerCategoryChangeNums_<%=category.get("CategoryId")%>" class="<%=moreClass%>"><td class="member" title="<%=Util.HTMLEncode((String)category.get("CategoryName"))%>"><%=Util.HTMLEncode(Util.showMaxLen((String)category.get("CategoryName"), 6))%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	}
%>
              </table>
<%
	if (num > 5) {
%><div><a href="#customerCategoryChangeNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
            </tr></table>
        </div>
        <div class="header">客户分类修改统计（二）
          <div class="right" style="position:relative;padding:10px;">
            <div style="float:left;" class="input-prepend input-group"><span class="add-on input-group-addon"><i class="fa fa-calendar"></i></span><input type="text" id="searchDate_customer_change2" class="daterangepickerinput form-control" value="" /></div>
            <select id="category_change_categoryId" style="float:left;padding:4px 1px 4px 4px;margin-left:10px;">
              <option value="0">所有客户分类</option>
              <%
              	for (Map<String, Object> category:customerCategorys) {
              %>
              <option value="<%=category.get("CategoryId")%>"><%=Util.HTMLEncode(Util.showMaxLen((String)category.get("CategoryName"), 10))%></option>
              <%
              	}
              %>
            </select>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar"><div class="char" id="categorychangechar2"></div></td>
            <td class="lineChar second">
              <h1>员工列表详细 <span id="totalCategoryChangeNums2"></span></h1>
              <table id="customerCategoryChangeNums2">
<%
	index = 0;
  for (User u:listUsers) {
    if (index < 5) {
%>
              <tr v="0" id="customerCategoryChangeNums2_<%=u.userId%>"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	  } else {
%>
              <tr v="0" id="customerCategoryChangeNums2_<%=u.userId%>" class="more"><td class="member"><%=Util.HTMLEncode(u.name)%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%
	  }
    index++;
  }
%>
              </table>
<%
	if (index > 5) {
%><div><a href="#customerCategoryChangeNums2" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%
	}
%>
            </td>
            </tr></table>
        </div>
        <div class="header">客户标签统计
          <div class="right date">
            <select id="tag_userId">
            <%
            	if (user.isAdmin()) {
            %>
              <option value="">所有数据（包含公海数据）</option>
              <option value="u_*">所有员工</option>
              <option value="g_0">无部门员工</option>
              <%
                for (User u:listUsers) {
                  if (u.groupId == 0) {
              %>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%
              	  }
                }
              } else if (user.isGroupAdmin()){%>
              <option value="t_<%=user.groupId%>">所有员工</option>
             <%}
              for (Group gp:listGroups) {%>
              <option value="g_<%=gp.getId()%>">部门：<%=Util.HTMLEncode(gp.getName())%></option>
              <%
                for (User u:listUsers) {
                  if (u.groupId == gp.getId()) {
                  %>
              <option value="u_<%=u.userId%>">&nbsp;&nbsp;&nbsp;&nbsp;员工：<%=Util.HTMLEncode(u.name)%></option>
              <%  }
                }
              }
              %>
            </select>
          </div>
        </div>
        <div class="lineChar-container">
          <table><tr>
            <td class="lineChar"><div class="char" id="tagchar"></div></td>
            <td class="lineChar second">
              <h1>客户标签详细  <span id="totalTagNums"></span></h1>
              <table id="customerTagNums">
<%
num = 0;
moreClass = "";
for (Map<String, Object> tag:companyTags) {
  if (num > 4) {
    moreClass = "more";
  }
  num ++;
%>
              <tr v="0" id="customerTagNums_<%=tag.get("TagId")%>" class="<%=moreClass%>"><td class="member" title="<%=Util.HTMLEncode((String)tag.get("TagName"))%>"><%=Util.HTMLEncode(Util.showMaxLen((String)tag.get("TagName"), 6))%></td><td class="line"><div class="progress"><div class="progress-bar"></div></div><span></span></td><td class="rate">0%</td></tr>
<%}%>
              </table>
<%if (num > 5) {%><div><a href="#customerTagNums" class="showall"><i class="fa fa-angle-double-down"></i> 查看全部</a></div><%}%>
            </td>
            </tr></table>
        </div>
      </td>
    </tr>
    </table>
  </div>


  <div id="voip-time-popup" class="white-popup mfp-hide">
    <div class="popup-title"><span class="title">设置统计的通话时长</span> <span class="popup-close-button"><i class="fa fa-times"></i>&nbsp;</span></div>
    <div class="popup-content">
      <div><label for="voip-seconds">通话时长（秒）：</label><input type="text" value="" v="" id="voip-seconds"></div>
    </div>
    <div class="buttonbar">
      <div class="right">
        <a id="voip-time-link" class="button blue small" href="#"><i class="fa fa-check"></i> 确定</a>
        <a class="button grey small popup-close-button" href="#"><i class="fa fa-times"></i> 取消</a>
      </div>
    </div>
  </div>

</body>
</html>